String clazzTpl({package}) => """
import 'dart:io';
import 'app_debug_model.dart';
import 'package:xanno/xanno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:$package/route/main.route.dart';
import 'package:$package/widget/theme_builder.dart';
import 'package:$package/store/theme/theme_state.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

@GRoute(url: '/appErrorLog', title: 'AppErrorLog')
class AppErrorLogPage extends StatefulWidget {
  final String title;

  const AppErrorLogPage({Key? key, required this.title}) : super(key: key);

  @override
  _AppErrorLogPageState createState() => _AppErrorLogPageState();
}

class _AppErrorLogPageState extends State<AppErrorLogPage> {
  List<FileSystemEntity> _files = [];
  List<String> _contentList = [];
  String _title = '';

  void _deleteItem(BuildContext context, FileSystemEntity item) {
    final fileOrDir =
        FileSystemEntity.isFileSync(item.path) ? 'file' : 'directory';
    final fileName = item.path.split(Platform.pathSeparator).last;
    ScaffoldMessenger.of(context)
      ..hideCurrentSnackBar()
      ..showSnackBar(
          SnackBar(content: Text('delete \$fileOrDir [\$fileName] success')));
    File(item.path).deleteSync(recursive: true);
    setState(() {
      _files.remove(item);
    });
  }

  Widget _fileContent(Color titleColor, Color bodyColor) {
    return ListView.builder(
      padding: EdgeInsets.all(16),
      itemCount: _contentList.length,
      itemBuilder: (context, index) =>
          Text(_contentList[index], style: TextStyle(color: titleColor)),
    );
  }

  Widget _dirList(Color titleColor, Color bodyColor) {
    return ListView.separated(
      itemCount: _files.length,
      separatorBuilder: (BuildContext context, int index) {
        return Divider(height: 1);
      },
      itemBuilder: (BuildContext context, int index) {
        FileSystemEntity item = _files[index];
        return GestureDetector(
          onTap: () async {
            final name = item.path.split(Platform.pathSeparator).last;
            if (FileSystemEntity.isFileSync(item.path)) {
              Navigator.pushNamed(context, RouteConstant.AppErrorLogPage,
                  arguments: ErrorLogFileModel(
                      path: item.path,
                      title: name.split('.').first,
                      isFile: true));
            } else {
              Navigator.pushNamed(context, RouteConstant.AppErrorLogPage,
                  arguments: ErrorLogFileModel(
                      path: item.path, title: name, isFile: false));
            }
          },
          child: Slidable(
            key: Key(item.path),
            dismissal: SlidableDismissal(
              child: SlidableDrawerDismissal(),
              onDismissed: (actionType) => _deleteItem(context, item),
            ),
            actionPane: SlidableDrawerActionPane(),
            actionExtentRatio: 0.25,
            secondaryActions: <Widget>[
              IconSlideAction(
                caption: '删除',
                color: Colors.red,
                icon: Icons.delete,
                onTap: () => _deleteItem(context, item),
              ),
            ],
            child: Container(
              color: titleColor.withOpacity(0.8),
              child: ListTile(
                title: Text(
                  item.path.split(Platform.pathSeparator).last,
                  style:
                      TextStyle(color: bodyColor, fontWeight: FontWeight.bold),
                ),
//                tileColor: titleColor.withOpacity(0.8),
                trailing: Icon(Icons.keyboard_arrow_right,
                    size: 30, color: bodyColor),
              ),
            ),
          ),
        );
      },
    );
  }

  @override
  void didChangeDependencies() {
    ErrorLogFileModel fileModel =
        ModalRoute.of(context)!.settings.arguments as ErrorLogFileModel;
    _title = fileModel.title; 
    if (fileModel.isFile) {
      File(fileModel.path).readAsLines().then((value) {
        setState(() {
          _contentList = value;
        });
      });
    } else {
      //create time sort
      Directory(fileModel.path).list().toList().then((value) {
        value.sort(
            (a, b) => (b.statSync().modified).compareTo(a.statSync().modified));
        setState(() {
          _files = value;
        });
      });
    }
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    return ThemeBuilder(builder: (context, theme) {
      return Scaffold(
        backgroundColor: theme.body,
        appBar: AppBar(
          brightness: theme.type == ThemeType.light
              ? Brightness.light
              : Brightness.dark,
          backgroundColor: theme.body,
          iconTheme: IconThemeData(color: theme.title, opacity: 1),
          title: Text(_title, style: TextStyle(color: theme.title)),
        ),
        body: _files.isEmpty
            ? _fileContent(theme.title, theme.body)
            : _dirList(theme.title, theme.body),
      );
    });
  }
}
""";
